from django.shortcuts import render

from django.shortcuts import HttpResponse

from cmdb import models

from cmdb import Utils

# Create your views here.


success_list = [
    {'status':'200','success':'true'}
]

false_list = [
    {'status':'201','success':'false'}
]

def register(request):

    #return HttpResponse('hello,world!!')

    if request.method == "POST":
        username = request.POST.get('userName',None)
        password = request.POST.get('password',None)
        email = request.POST.get('email',None)

        pwd_md5 = Utils.encryption(password)

        user = models.userInfo(userName=username,userPwd=pwd_md5,userEmail=email) #存入数据库

        user.save()

        user = models.userInfo.objects.get(userName=username)

        name = user.userName

        pwd = user.userPwd

        Email = user.userEmail

        userList = [
            {'用户名':name,'密码':pwd,'邮箱':Email}
        ]

        # if username == 'admin' and password == '123456':
        #
        #     return HttpResponse(success_list)
        # else:
        #
        #     return HttpResponse(false_list)
        return HttpResponse(userList)
    return render(request, 'index.html')